package edu.suse.controller;

import edu.suse.common.base.RespResult;
import edu.suse.entity.SysDept;
import edu.suse.service.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys_dept")
@Api(value = "部门数据test",tags = "部门操作接口API")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @GetMapping("findSysDeptAll")
    public RespResult findSysDeptAll() {
        return sysDeptService.findSysDeptAll();
    }

    @GetMapping("/findOneSysDept")
    public RespResult findOneSysDept(int id) {
        return sysDeptService.findOneSysDept(id);
    }

    @GetMapping("/insertSysDept")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "部门名称", paramType = "query", required = true),
            @ApiImplicitParam(name = "sort", value = "序号", paramType = "query", required = true)
    })
    public RespResult insertSysDept(SysDept sd) {
        return sysDeptService.insertSysDept(sd);
    }

    @GetMapping("/deleteSysDept")
    public RespResult deleteSysDept(int id) {
        return sysDeptService.deleteSysDept(id);
    }

    @GetMapping("/updateSysDept")
    public RespResult updateSysDept(String title, int sort, String remark, int status, int id) {
        return sysDeptService.updateSysDept(title, sort, remark, status, id);
    }


    @GetMapping("/findAll")
    public RespResult findPage(Integer page, Integer pageSize) {
        page = (page - 1) * pageSize;
        return sysDeptService.selectAll(page, pageSize);
    }

    @GetMapping("/loadPage")
    public int loadPage() {
        System.out.println(sysDeptService.loadPage());
        return sysDeptService.loadPage();
    }

}
